<?php
class UpdateController extends Zend_Controller_Action 
{
    
    
    
    public function tablesAction()
    {
        $app = Led_Application::getInstance();
     
        $app->getDb()->query('DROP TABLE IF EXISTS edo');
        $app->getDb()->query('DROP TABLE IF EXISTS edo_type');
           
        Zend::loadClass('Lead_Sql_Executor');
        Lead_SQL_Executor::execute($app->getDb(), '/wwwroot/LEAD/library/Lead/EDO/Schema/static.sql');
         
        $sql = "INSERT INTO edo_type SELECT typeid, rawname, 0 FROM led_enttypes";
        $app->getDb()->query($sql);
        
        $sql = "INSERT INTO edo SELECT entid, typeid FROM led_entlist";
        $app->getDb()->query($sql);        
               
        $tables = $app->getDb()->listTables();
        
        foreach($tables as $table) {
            
            if(substr($table, 0, 3) == 'ent') {
                
                $sql = "ALTER TABLE {$table} CHANGE COLUMN entid id integer NOT NULL";
                $app->getDb()->query($sql);
              
                $sql = "ALTER TABLE {$table} ADD FOREIGN KEY(id) REFERENCES edo(id) ON UPDATE CASCADE ON DELETE CASCADE";
                $app->getDb()->query($sql);
                
                try {
                    
                    $sql = "ALTER TABLE {$table} CHANGE COLUMN langid_multi dimension_id integer NOT NULL";
                    $app->getDb()->query($sql);
                    
                } catch(Exception $e) {
                    print "laa";
                }
                
                
            }
        }
        
        
        
        
                
        
        
    }
    
    
}